const path = require('path');
const { sep } = path;
const glob = require('glob');
/**
 * 加载路由规则配置
 * @param {*} app Elpis应用实例
 */
module.exports = (app) => {
    const routerSchemaPath = path.resolve(app.bisinessPath, `.${sep}router-schema`);
    const fileList = glob.sync(path.resolve(routerSchemaPath, `.${sep}**${sep}**.js`));
    /**
     * 路由配置对象
     * 路由配置对象的结构与路由配置文件的目录结构相同
     * 该目录规定了不是嵌套的文件
     */
    let routerSchema = {};
    fileList.forEach((file) => {
        const schema = require(file);
        routerSchema = {...routerSchema, ...schema}
    })
    app.routerSchema = routerSchema;
}